package com.example.hospital.api.service.impl;

import cn.hutool.core.map.MapUtil;
import com.example.hospital.api.common.PageUtils;
import com.example.hospital.api.db.dao.MedicalRegistrationDao;
import com.example.hospital.api.service.RegistrationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Map;

@Service
@Slf4j
public class RegistrationServiceImpl implements RegistrationService {
    @Resource
    private MedicalRegistrationDao medicalRegistrationDao;
    @Override
    public PageUtils searchRegistrationByPage(Map param) {
        ArrayList list = null;
        long count = medicalRegistrationDao.searchRegistrationCount(param);
        if (count > 0) {
            list = medicalRegistrationDao.searchRegistrationByPage(param);
        } else {
            list = new ArrayList();
        }
        int page = MapUtil.getInt(param, "page");
        int length = MapUtil.getInt(param, "length");
        PageUtils pageUtils = new PageUtils(list, count, page, length);
        return pageUtils;
    }

    @Override
    public PageUtils searchRegistrationByPages(Map param) {
        ArrayList list = null;
        long count = medicalRegistrationDao.searchRegistrationCounts(param);
        if (count > 0) {
            list = medicalRegistrationDao.searchRegistrationByPages(param);
        } else {
            list = new ArrayList();
        }
        int page = MapUtil.getInt(param, "page");
        int length = MapUtil.getInt(param, "length");
        PageUtils pageUtils = new PageUtils(list, count, page, length);
        return pageUtils;
    }
}
